﻿namespace Bronze.Network
{
    using System;
    using System.Net;
    using System.Net.Sockets;

    public class ClientConnection
    {
        private const int cBufferSize = 1024;
        public int ConnectionId;
        private byte[] mBuffer;
        private IPEndPoint mEndPoint;
        private System.Net.Sockets.Socket mSocket;

        public ClientConnection(System.Net.Sockets.Socket socket)
        {
            this.mSocket = socket;
            this.mEndPoint = (IPEndPoint)socket.RemoteEndPoint;
            this.mBuffer = new byte[1024];
        }

        private int retryCount = 0;

        /// <summary>
        /// 重试次数
        /// </summary>
        public int RetryCount
        {
            get { return retryCount; }
            set { retryCount = value; }
        }

        public byte[] Buffer
        {
            get
            {
                return this.mBuffer;
            }
        }

        public IPEndPoint EndPoint
        {
            get
            {
                return this.mEndPoint;
            }
        }

        public System.Net.Sockets.Socket Socket
        {
            get
            {
                return this.mSocket;
            }
        }


        private ClientStatus _clientStatus = ClientStatus.Unknown;
        public ClientStatus ClientStatus
        {
            get
            {
                return _clientStatus;
            }
            set
            {
                _clientStatus = value;
            }
        }

        private DateTime _createTime;

        /// <summary>
        /// 连接创建时间
        /// </summary>
        public DateTime CreateTime
        {
            get
            {
                return this._createTime;
            }
            set
            {
                this._createTime = value;
            }
        }

        private DateTime _lastSendActiveTestTime = DateTime.MinValue;

        /// <summary>
        /// 最后一次发送激活测试的时间
        /// </summary>
        public DateTime LastSendActiveTestTime
        {
            get { return _lastSendActiveTestTime; }
            set { _lastSendActiveTestTime = value; }
        }

        private DateTime _lastActiveTestResponseTime = DateTime.MinValue;
        /// <summary>
        /// 最后一次收到激活测试的时间
        /// </summary>
        public DateTime LastActiveTestResponseTime
        {
            get
            {
                return this._lastActiveTestResponseTime;
            }
            set
            {
                this._lastActiveTestResponseTime = value;
            }
        }


        private DateTime _listSendTime = DateTime.MinValue;
        public DateTime LastSendTime
        {
            get
            {
                return this._listSendTime;
            }
            set
            {
                this._listSendTime = value;
            }
        }

        private DateTime lastReciveTime;
        /// <summary>
        /// 最后接收到数据包时间
        /// </summary>
        public DateTime LastReciveTime
        {
            get { return lastReciveTime; }
            set { lastReciveTime = value; }
        }

        private object tag;

        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        /// <summary>
        /// 接收到脏数据的次数，防止恶意攻击
        /// </summary>
        public int DirtyDataCount
        {
            get;
            set;
        }


 
    }

    public enum ClientStatus
    {
        Unknown = 0,
        Online = 1,
        Offline = 2

    }
}

